package com.nf.health.app.activity.my;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.activity.global.BaseActivity;
import com.nf.health.app.activity.my.adapter.GridHouseResponblePresionAdapter;
import com.nf.health.app.customview.EmptyView;
import com.nf.health.app.customview.MyListView;
import com.nf.health.app.http.Act;
import com.nf.health.app.models.HouseResponblePresion;
import com.nf.health.app.utils.ViewUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;


/**
 * 家庭责任人
 * @author 于亚豪
 */

public class HourseReponsibilePersionActibity   extends BaseActivity {
    @Bind(R.id.lr_recycleView_query)
    MyListView lr_recycleView_query;
   // private HouseResponblePresionAdapter houseResponblePresionAdapter  = null;
    private GridHouseResponblePresionAdapter gridHouseResponblePresionAdapter  = null;
    private   List<HouseResponblePresion> list;
    private    View emptyView = null;
    private LayoutInflater inflater;

    TextView tv_empty;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitleBar(R.layout.titlebar_base);
        setContent(R.layout.activity_hoursere_ponsibile_persion);
        ButterKnife.bind(this);
        ViewUtil.setText(this, R.id.titlebar_title_tv, "健康明白人");
        initViews();
        loadData("");
    }
    private void initViews(){
        list = new ArrayList<>();
        gridHouseResponblePresionAdapter = new GridHouseResponblePresionAdapter(HourseReponsibilePersionActibity.this,list);
        lr_recycleView_query.setAdapter(gridHouseResponblePresionAdapter);
        inflater = LayoutInflater.from(this);
        emptyView =inflater.inflate(R.layout.empty_nodata,null);
        tv_empty = (TextView) emptyView.findViewById(R.id.tv_empty);
        tv_empty.setText("暂无数据");
        /*lr_recycleView_query.setItemAnimator(new MyMainItemAnimation());
        lr_recycleView_query.setLayoutManager(new GridLayoutManager(HourseReponsibilePersionActibity.this,3));
        lr_recycleView_query.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader);
        lr_recycleView_query.setArrowImageView(R.drawable.ic_pulltorefresh_arrow);
        DividerGridItemDecoration dividerGridItemDecoration = new DividerGridItemDecoration(this);
        dividerGridItemDecoration.setMyDividerGridItemDecorationColor(ContextCompat.getColor(this,R.color.red));
        lr_recycleView_query.addItemDecoration(new DividerGridItemDecoration(this));
        lr_recycleView_query.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh() {
                RecyclerViewStateUtils.setFooterViewState(lr_recycleView_query, LoadingFooter.State.Normal);
                loadData(Act.Flag.FLAG_REFRESH_DATA);
            }
        });
        lr_recycleView_query.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore() {

                LoadingFooter.State state = RecyclerViewStateUtils.getFooterViewState(lr_recycleView_query);
                if(state == LoadingFooter.State.Loading) {
                    return;
                }
            }
        });*/
    }
        private void loadData(String actionName ){
            provider.getHourseResponsible();
        }
    @Override
    public void handleActionSuccess(String actionName, Object object) {
        super.handleActionSuccess(actionName, object);
        switch (actionName){
            case Act.Flag.FLAG_HOURSE_RESPONSIBLE_PERSON:
                 list = (List<HouseResponblePresion>) object;
                if(list== null || list.size() == 0){//加载空布局
                    try {
                        EmptyView emptyView = new EmptyView(this);
                        emptyView.mustCallInitWay(lr_recycleView_query);
                        lr_recycleView_query.setEmptyView(emptyView);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }else{
                    if(gridHouseResponblePresionAdapter == null){
                        gridHouseResponblePresionAdapter = new GridHouseResponblePresionAdapter(HourseReponsibilePersionActibity.this,list);
                        lr_recycleView_query.setAdapter(gridHouseResponblePresionAdapter);
                    }else{
                        gridHouseResponblePresionAdapter.setMyNOtifuDataChanged(list);
                    }
                }
        }
    }
}
